package com.hopu.shop.controller;

import com.alibaba.fastjson.JSON;
import com.feng.common.controller.CommonController;

import com.feng.common.util.Result;
import com.feng.common.util.ResultPage;
import com.hopu.shop.server.ShopTypeServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.Map;

/**
* @Description: ShopController 商品信息管理模块
* @Author: xing
* @Date: 2023/2/6 14:52
*/
@Controller
@RequestMapping("/shoptype")
public class ShopTypeController extends CommonController {


    @Autowired
    ShopTypeServer shopTypeServer;

    @RequestMapping(value = "/typequery",method = RequestMethod.GET)
    @ResponseBody
    public String shoptype_query(@RequestParam Map map) throws Exception {
        Result result = new Result();

        //分页
        String page = map.get("page").toString();
        String limit = map.get("limit").toString();
        page = (Integer.valueOf(page)-1)*Integer.valueOf(limit)+"";
        map.put("page",page);

        System.out.println("map===="+map);
        result.setCode("0");
        result.setData(shopTypeServer.typequery(map));
        result.setCount(shopTypeServer.count(map).get("count")+"");

        return JSON.toJSONString(result);
    }


    /**
     * 修改
     * @param map
     * @return
     */
    @RequestMapping("/typeupd")
    @ResponseBody
    public String upd(@RequestParam Map map) throws Exception {
        System.out.println("mao1="+map);
        Result result = new Result();
        result.setCode("0");
        result.setData(Collections.singletonList(shopTypeServer.typeupd(map)));
        return JSON.toJSONString(result);


    }

    /**
     * 新增
     * @param map
     * @return
     * @throws Exception
     */
    @RequestMapping("/typesava")
    @ResponseBody
    public String sava(@RequestParam Map map)throws Exception{
        System.out.println("进入新增的方法");
        System.out.println("map="+map);
        Result result = new Result();
        result.setCode("1");
        result.setData(Collections.singletonList(shopTypeServer.typesava(map)));
        result.setShop_info_id(map.get("shop_type_id"));

        return JSON .toJSONString(result);
    }

    /**
     * 删除
     */

    @RequestMapping("/typedel")
    @ResponseBody
    public String del(@RequestParam Map map)throws Exception{
        System.out.println("进入了删除的方法");
        Result result = new Result();
        result.setCode("1");
        result.setData(Collections.singletonList(shopTypeServer.typedel(map)));
        return  JSON .toJSONString(result);
    }


    @RequestMapping("/tiao")

    public String tiao(){
        return "/type/index.html";
    }
}
